package lm.demo.agent;

import java.util.List;
import java.util.Objects;

public class attach {
    public static void main(String[] args) {
        VirtualMachine vm;
        List<VirtualMachineDescriptor> listAfter;
        String jar = "C:\\Users\\admin\\Desktop\\wrokspace\\DemoAgent\\target\\DemoAgent-1.0-SNAPSHOT.jar";
        int count = 0;

        try {
            while (true) {
                vm = VirtualMachine.attach("12280");

                Thread.sleep(1000);
                System.out.println(count++);
                if (null != vm || count >= 100) {
                    break;
                }
            }
            Objects.requireNonNull(vm).loadAgent(jar);
            vm.detach();
        } catch (Exception e) {
            System.out.println("异常：" + e);
        }
    }
}
